import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 8002))
sock.listen(5)
while True:
    connect, addr = sock.accept()
    try:
        connect.settimeout(5)
        buf = connect.recv(1024)
        print(buf)
        # if buf == b'1':
        # connect.send(b'welcome to server')
        # else:
        # connect.send(b'please go out')
        connect.send(buf)
    except socket.timeout:
        print('time out')
    connect.close()
